﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

using FrbaBus.Core;
namespace FrbaBus.GenerarViaje
{
    public partial class Seleccionar_Recorrido : Form
    {
        GenerarViaje originalForm;
        public Seleccionar_Recorrido(GenerarViaje incomingForm)
        {
            originalForm = incomingForm;
            InitializeComponent();
        }
                    
        private void Seleccionar_Recorrido_Load(object sender, EventArgs e)
        {
            dataGridView1.ReadOnly = true;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AllowUserToDeleteRows = false;
            dataGridView1.Rows.Clear();
            DBManager db = new DBManager();
            SqlCommand consulta = new SqlCommand("select ID_Recorrido, Origen, Destino, Tipo_Servicio, Precio_Pasaje_Base, Precio_Kg_Base from ALL_IN.Recorrido where Habilitado=1");
            SQLResponse r = db.executeQuery(consulta);
            SqlCommand consulta2 = new SqlCommand("select count (*) from ALL_IN.Recorrido where Habilitado=1");
            SQLResponse r2 = db.executeQuery(consulta2);
            int valor = (int)r2.result.Rows[0][0];
            for (int i = 0; i < valor; i++)
            {
                dataGridView1.Rows.Add(r.result.Rows[i][0].ToString(), r.result.Rows[i][1].ToString(), r.result.Rows[i][2].ToString(), r.result.Rows[i][3].ToString(), r.result.Rows[i][4].ToString(), r.result.Rows[i][5].ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            originalForm.Origen = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString();
            originalForm.Destino = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[2].Value.ToString();
            originalForm.IDRecorrido = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
            originalForm.TipoServicio = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[3].Value.ToString();
            originalForm.populate2();
            this.Close();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }


    }
}
